#include <time.h>

extern XFont *_xFont; 
extern TFT_eSPI tft;   
extern TFT_eSprite spr;

struct tm timeinfo;

// 自定义周几和月份的中文字符串数组
const char *week_day[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
const char *month_name[] = {"", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};

// 将tm结构体中的日期信息转化为中文显示的字符串
extern const char *formatChineseDate(const struct tm *timeinfo)
{
    static char result[50]; // 静态数组保存结果
    snprintf(result, sizeof(result), "%s %s%d日", week_day[timeinfo->tm_wday], month_name[timeinfo->tm_mon + 1], timeinfo->tm_mday);
    return result;
}


extern void printDate(){
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time!");
    return;
  }
  spr.setColorDepth(8);     // 局部刷新屏幕
  spr.createSprite(60, 20);
  spr.fillSprite(TFT_WHITE);
  spr.pushSprite(10, 60);
  spr.deleteSprite();

  const char *date = formatChineseDate(&timeinfo);
  _xFont->DrawChinese(10, 60, date, TFT_BLACK);
}



extern void printLocalTime(){
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time!");
    return;
  }
  tft.setCursor(10, 10, 7);
  tft.setTextColor(TFT_BLACK, TFT_WHITE);
  tft.println(&timeinfo, "%H:%M");
  tft.setTextFont(2);

}
